Jest "Cannot find module from xxx" issue


Posted by tsungtingdu on 2021-07-16

在跑測試的時候,遇到了下面的錯誤

Cannot find module 'abc' from '.../xyz.component.ts'

問題在於 Jest 測試 xyz.component 的時候找不到我們在當中引入的第三方 AbcComponent

xyz.component

import { AbcComponent } from 'abc-path';

這時候需要在 jest.config 當中建立 moduleNameMapper

jest.config.js

  moduleNameMapper: {
    "abc": "abc-path"
  },

#Angular #Jest







Related Posts

[day-2] JS 環境建立流程/賦值運算子/字串型別

[day-2] JS 環境建立流程/賦值運算子/字串型別

【THM Walkthrough】Exploiting Active Directory (1)

【THM Walkthrough】Exploiting Active Directory (1)

# 〈 Diffusion Model 論文研究與實作心得 Part.2 〉 U-Net 模型架構介紹與實作

# 〈 Diffusion Model 論文研究與實作心得 Part.2 〉 U-Net 模型架構介紹與實作


Comments